#ifndef HTTP_CLIENT_H
#define HTTP_CLIENT_H
#include <QtGui>
#include <QObject>
#include <QFile>
#include <QApplication>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QUrl>
#include <stdlib.h>
#include <stdio.h>
//TODO http://www.siteduzero.com/informatique/tutoriels/le-protocole-http-avec-qtnetwork/le-telechargement-des-donnees-avec-get
class http_client : public QObject
{
    Q_OBJECT
public:
    explicit http_client(QObject *parent = 0);
    ~http_client();
signals:
    void send_filename_from_url(QString);
    void send_content(QString);
    void send_filename_with_url(QString);
    void end_download(void);
    void connecte(void);
    void fin_de_get(void);
    void send_content_req_to_parse(const QByteArray);
    void finish_post();
    void send_add(QString);
    void finish_export(void);
    void send_state_http_get(int);
    //void send_reply(QNetworkReply);
public slots:
    void save();
    void network_get_request(QString addr,QString chemin_xml,QString ua);
    void network_post_request(QString add, QString post_directory_path, QString message, QString cookie_value, QString ua);
    //void download_file(QString );
    void create_network();
    //void get_requete_backend(QString )
    void create_request(QString add);
    void http_request_get(QString add, QString file, QString user_agent);
    void http_request_post(QString add, QString post_directory_path, QString message, QString cookie_value, QString ua);
    //void telecharge(QString buff,QString file);
    void set_add(QString add);
    /*void set_xml_file(QString filename);
    void set_cookie(QString cookie);
    void set_ua(QString ua);*/
    void Erreur(QNetworkReply::NetworkError);
    void telechargement(void);
    void export_content();
    void detruire_response(void);
    void detruire_response_post(void);
    //void save_file(void);
private slots :
    void receive_file_name_from_download(QString file);
    void end_download_ok(void);
    void fin_de_requete_post(void);
    void receive_add(QString add);
protected:
    QNetworkReply *http_get_request(const QNetworkRequest & requete);
    QNetworkReply *http_post_request(const QNetworkRequest &requete,QString &postData);
private :
    void InitRequest(QUrl url);
    QFile fichier_xml;
    QString xml_file;
    QString fichier_a_parser;
    QString post_path_uri;
    QUrl url;
    QNetworkRequest requete;
    QString data;
    QString outfile;
    QNetworkReply *reponse;
    QNetworkReply *reponse_post;
    QNetworkAccessManager *network_conn;
    QVariant code_de_status;
    QVariant addresse_de_redirection;
    QString url_xml;
    QString hostname;
    QNetworkReply *reply;
    QNetworkAccessManager *qnam;
    QString user_agent;
    QFileInfo file_www;
    void get_file_with_param(QString add);
    bool error;
    bool end;
    
};

#endif // HTTP_CLIENT_H
